package aiyh.utils.mapUtil;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @author EBU7-dev1-ayh
 * @date 2021/8/23 0023 15:06
 * LinkedHashMap
 */


public class UtilLinkedHashMap<K, V> extends LinkedHashMap<K, V> implements Map<K, V> {
	public UtilLinkedHashMap() {
		super();
	}

	public UtilLinkedHashMap<K, V> uPut(K key, V value) {
		this.put(key, value);
		return this;
	}


	public UtilLinkedHashMap<K, V> uPutAll(Map<? extends K, ? extends V> m) {
		super.putAll(m);
		return this;
	}

	public UtilLinkedHashMap<K, V> uReplace(K key, V value) {
		super.replace(key, value);
		return this;
	}

	public UtilLinkedHashMap<K, V> filter(UtilMapFilter<? super K, ? super V> predicate) {
     UtilLinkedHashMap<K, V> newMap = new UtilLinkedHashMap<>();
		for (Entry<K, V> entry : this.entrySet()) {
			if (predicate.test(entry.getKey(), entry.getValue())) {
				newMap.put(entry.getKey(), entry.getValue());
			}
		}
		return newMap;
	}
}
